﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;

namespace MidSoft.Sys.Organize
{
    public partial class Modify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int OrganizeId = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(OrganizeId);
                }
            }
        }

        private void ShowInfo(int OrganizeId)
        {
            ChinaSoft.BLL.BLL_tb_MidSoft_Organize bll = new ChinaSoft.BLL.BLL_tb_MidSoft_Organize();
            ChinaSoft.Model.Model_tb_MidSoft_Organize model = bll.GetModel(OrganizeId);
            this.txtOrganizeName.Text = model.OrganizeName;
        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtOrganizeName.Text.Trim().Length == 0)
            {
                strErr += "组织（公司名称）不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int OrganizeId = ChinaSoft.Common.Input.SetInt(Request.Params["id"]);
            #region 修改
            ChinaSoft.BLL.BLL_tb_MidSoft_Organize bll = new ChinaSoft.BLL.BLL_tb_MidSoft_Organize();
            ChinaSoft.Model.Model_tb_MidSoft_Organize model = bll.GetModel(OrganizeId);
            model.OrganizeName =this.txtOrganizeName.Text;

            bll.Update(model);
            #endregion

            #region 添加日志
            ChinaSoft.Model.Model_tb_MidSoft_log modelLog = new ChinaSoft.Model.Model_tb_MidSoft_log();
            ChinaSoft.BLL.BLL_tb_MidSoft_log bllLog = new ChinaSoft.BLL.BLL_tb_MidSoft_log();
            modelLog.userAccount = "";
            if (Session["UserAccount"] != null && Session["UserAccount"].ToString() != "")
                modelLog.userAccount = Session["UserAccount"].ToString();
            modelLog.userName = "";
            if (Session["UserName"] != null && Session["UserName"].ToString() != "")
                modelLog.userName = Session["UserName"].ToString();
            modelLog.description = "组织机构信息修改,ID=" + OrganizeId;
            modelLog.LogType = 2;
            modelLog.CreateTime = DateTime.Now;
            bllLog.Add(modelLog);
            #endregion
            Response.Write("<script>alert('成功！');top.window.parent.frames.item('workspace').location.reload();window.parent.$('#DivSysiframe').dialog(\"close\");</script>");
        }
    }
}